package book

//ISBN\x20(?=.{13}$)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)$
class Book {
	String title
	String author
	String description
	String isbn
	String language 
	BookCat category
	int minGrade
	int maxGrade
	
    static constraints = {
		title(blank:false)
		author(blank:false)
		description(blank:true)
		language(blank:true)
		category(blank:false)
		minGrade(range:0..6, blank:false)
		maxGrade(range:0..6, blank:false)
		isbn(
			blank:true,
			validator: {
				def pattern = (it =~ /ISBN\x20(?=.{13}$)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)$/)
				return pattern.matches() || it == ""
			}
		)
    }
}

enum BookCat{
	GeneralLeisureReading("General Leisure Reading"),
	ReadingSkills("Reading Skills"),
	MathSkills("Math Skills"),
	Health("Health"),
	Science("Science")
	
	final String value
	
	BookCat(String value)
	{
		this.value=value
	}
}

